package com.powernode.controller;

import com.powernode.framework.Result;
import com.powernode.framework.ResultUtil;
import com.powernode.pojo.FloorAdmin;
import com.powernode.pojo.TowerAdmin;
import com.powernode.service.RecentGraphService;
import com.powernode.utils.DateUtil;
import com.powernode.vo.HospitalStatVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Hanyixuan
 */
@RestController
@RequestMapping("/api/recentGraph")
public class RecentGraphController {
    @Autowired
    RecentGraphService recentGraphService;
    @GetMapping("/getHospitalStat")
    public Result<Map<String,Object>> getBorrowStat(HttpServletRequest request){

        FloorAdmin floorAdmin = (FloorAdmin)request.getSession().getAttribute("floorAdmin");
        String floorSite = floorAdmin.getFloorSite();


        Map<String,Object> map = new HashMap<>(16);
        List<String> days = DateUtil.getDaysBetwwen(7);
        map.put("columnName",days);
        HospitalStatVO xinguanVO = new HospitalStatVO();
        HospitalStatVO aiziVO = new HospitalStatVO();
        xinguanVO.setName("新冠肺炎");
        aiziVO.setName("肺结核");
        xinguanVO.setType("bar");
        aiziVO.setType("bar");
        List<Integer> xinguanData = new ArrayList<>();
        List<Integer> aiziData = new ArrayList<>();
        for (String day:days) {
            xinguanData.add(recentGraphService.getxinguanCount(day,floorSite));
            aiziData.add(recentGraphService.getaiziCount(day,floorSite));
        }
        xinguanVO.setData(xinguanData);
        aiziVO.setData(aiziData);
        List<HospitalStatVO> list = new ArrayList<>();
        list.add(xinguanVO);
        list.add(aiziVO);
        map.put("columnValue",list);
        return ResultUtil.ok(map);
    }
}
